package patterns.service;

/**
 * Created by lenovo on 2016/12/12 0012.
 * 服务定位器
 */
public class ServiceLocator {
    private static Cache cache;

    static {
        cache = new Cache();
    }

    public static IService getService(String jndiName) {
        IService service = cache.getService(jndiName);
        if (service != null) {
            return service;
        }
        InitialContext context = new InitialContext();
        IService service1 = (IService) context.lookup(jndiName);
        cache.addServices(service1);
        return service1;
    }
}
